//
//  TCM_ShareView.swift
//  TCM_TradingProject
//
//  Created by 吕春海 on 2018/8/28.
//  Copyright © 2018年 lvchunhai. All rights reserved.
//

import UIKit

enum shareType {
    case wx,wxZone,qq
}

class TCM_ShareView: UIView {

    typealias callBack = ()->()
    var cancelClouser:callBack?
    var title:String?
    var descr:String?
    var thumbImage:UIImage?
    var webpageUrl:String?
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }

    @IBAction func wxZone(_ sender: UIButton) {
        handelShareEithType(.wx)
    }
    
    @IBAction func wxFriends(_ sender: UIButton) {
        handelShareEithType(.wxZone)
    }
    
    @IBAction func QQFriends(_ sender: UIButton) {
        handelShareEithType(.qq)
    }
    
    func handelShareEithType(_ type:shareType){
        let message:UMSocialMessageObject =  UMSocialMessageObject()
        let shareObject:UMShareWebpageObject = UMShareWebpageObject()
        var platformType:UMSocialPlatformType = UMSocialPlatformType(rawValue: 0)!
        shareObject.title = self.title
        shareObject.thumbImage = self.thumbImage
        shareObject.descr = self.descr
        shareObject.webpageUrl = self.webpageUrl
        message.shareObject = shareObject
        if type == .qq {
            platformType = .QQ
        }else if  type == .wx{
            platformType = .wechatSession
        }else if  type == .wxZone{
            platformType = .wechatTimeLine
        }
        UMSocialManager.default().share(to:platformType, messageObject: message, currentViewController: UIViewController.topViewController()) { (response, error) in
            if error != nil{
                BKLProgressHUD.showFail("分享失败", autoClear: true, autoClearTime: 2)
            } else{
                BKLProgressHUD.showSuccess("分享成功", autoClear: true, autoClearTime: 2)
            }
        }
        
    }
}
